package com.qms.qep.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.core.page.TableDataInfo;
import com.qms.qep.domain.Defect;
import com.qms.qep.service.IDefectService;

/**
 * 缺陷类型Controller
 */
@RestController
@RequestMapping("/qep/defect")
public class DefectController extends BaseController {
    @Autowired
    private IDefectService defectService;

    /**
     * 查询缺陷类型列表
     */
    @PreAuthorize("@ss.hasPermi('qep:defect:list')")
    @GetMapping("/list")
    public TableDataInfo list(Defect defect) {
        startPage();
        List<Defect> list = defectService.selectDefectList(defect);
        return getDataTable(list);
    }
    
    /**
     * 获取缺陷类型树列表
     */
    @PreAuthorize("@ss.hasPermi('qep:defect:list')")
    @GetMapping("/tree")
    public AjaxResult tree(Defect defect) {
        List<Defect> list = defectService.selectDefectTree(defect);
        return success(list);
    }

    /**
     * 获取缺陷类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('qep:defect:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(defectService.selectDefectById(id));
    }

    /**
     * 新增缺陷类型
     */
    @PreAuthorize("@ss.hasPermi('qep:defect:add')")
    @PostMapping
    public AjaxResult add(@RequestBody Defect defect) {
        return toAjax(defectService.insertDefect(defect));
    }

    /**
     * 修改缺陷类型
     */
    @PreAuthorize("@ss.hasPermi('qep:defect:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody Defect defect) {
        return toAjax(defectService.updateDefect(defect));
    }

    /**
     * 删除缺陷类型
     */
    @PreAuthorize("@ss.hasPermi('qep:defect:remove')")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id) {
        return toAjax(defectService.deleteDefectById(id));
    }
} 